<template>
  <text class="count-down-text" v-if="time">{{ time }}</text>
</template>

<script>
export default {
  props: {
    timestamp: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      time: 0,
    };
  },
  mounted() {
    this.time = parseInt(this.timestamp || 0);
    if (this.timestamp > 0) {
      this.timer = setInterval(() => {
        this.time--;
        if (this.time <= 0) {
          this.$emit("end");
          clearInterval(this.timer);
        }
      }, 1000);
    } else {
      this.$emit("end");
    }
  },
};
</script>

<style lang="stylus" scoped>
.count-down {
}
</style>